package com.ytoglobal.overseas.address.platform.model.response;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * <pre>
 * 名称: PageResponse
 * 描述: 分页对象
 * </pre>
 *
 * @author SunGao
 * @date: 2019/2/25
 * @since v1.0.0
 */

@Data
public class PageResponse<T> extends BaseResponse {


    /**
     * 每页大小
     */
    private int pageSize;

    /**
     * 总记录数
     */
    private long totalCount;

    /**
     * 总页数
     */
    private int totalPages;

    /**
     * 当前页面
     */
    private int currentPage;

    /**
     * 数据集合
     */
    private List<T> result;

    public PageResponse(Page<T> page) {
        this.pageSize = page.getPageSize();
        this.totalCount = page.getTotal();
        this.totalPages = page.getPages();
        this.currentPage = page.getPageNum();
        this.result = page.getResult();
    }

    public PageResponse(Map<String, Object> map) {
        this.currentPage = (Integer) map.get("currentPage");
        this.pageSize = (Integer) map.get("pageSize");
        this.totalPages = (Integer) map.get("totalPage");
        this.totalCount = Long.valueOf(map.get("totalCount").toString());
        this.result = (List) map.get("result");
    }
}
